﻿//////#include <iostream>
//////using namespace std;
//////
//////class Date
//////{
//////public:
//////	Date(int year = 1900, int month = 1, int day = 1)
//////	{
//////		_year = year;
//////		_month = month;
//////		_day = day;
//////	}
//////
//////	 Date(const Date& d)   //正确写法
//////	 //Date( Date d)  // 错误写法：编译报错，会引发无穷递归  因此 语法逻辑上会形成无穷递归 所以拷贝的参数必须使用引用
//////	{
//////		 cout << "Date(const Date& d)" << endl;
//////		//this->_year = d._year;
//////		_year = d._year;
//////		_month = d._month;
//////		_day = d._day;
//////	}
//////
//////	 void Print()
//////	 {
//////		 cout << _year << "-" << _month << "-" << _day << endl;
//////	 }
//////private:
//////	int _year = 1;
//////	int _month = 1;
//////	int _day = 1;
//////};
//////
////////自定义类型调用拷贝构造
//////void func1(Date d)
//////{
//////	d.Print();
//////}
//////
//////void func2(Date &d)
//////{
//////	d.Print();
//////}
//////
//////int main()
//////{
//////	// 自定义类型都要调用拷贝构造才能完成
//////	//Date d1; 
//////	//Date d2(d1);
//////	//d2.Print();
//////
//////	Date d1(2024, 4, 9);
//////	func1(d1);
//////	cout << endl;
//////
//////	Date d2(2024, 4, 9);
//////	func2(d2);
//////	cout << endl;
//////
//////	Date d3(d2);
//////	d2.Print();
//////	cout << endl;
//////	d3.Print();
//////	cout << endl;
//////
//////	Date d4 = d2;   //这也是拷贝构造,内置类型完成值拷贝
//////	d4.Print();
//////
//////
//////	return 0;
//////}
////
////
////
////
////
////
//////// ——————————————————浅拷贝
//////#include <iostream>
//////using namespace std;
//////class Time
//////{
//////public:
//////	Time()
//////	{
//////		_hour = 1;
//////		_minute = 1;
//////		_second = 1;
//////	}
//////	Time(const Time& t)
//////	{
//////		_hour = t._hour;
//////		_minute = t._minute;
//////		_second = t._second;
//////		cout << "Time::Time(const Time&)" << endl;
//////	}
//////private:
//////	int _hour;
//////	int _minute;
//////	int _second;
//////};
//////class Date
//////{
//////private:
//////	// 基本类型(内置类型)
//////	int _year = 1970;
//////	int _month = 1;
//////	int _day = 1;
//////	// 自定义类型
//////	Time _t;
//////};
//////int main()
//////{
//////	Date d1;
//////
//////	// 用已经存在的d1拷贝构造d2，此处会调用Date类的拷贝构造函数
//////	// 但Date类并没有显式定义拷贝构造函数，则编译器会给Date类生成一个默认的拷贝构造函数
//////	Date d2(d1);
//////	return 0;
//////}
////
////
////
////
//////  -------——————深拷贝
////#include <iostream>
////using namespace std;
////
////typedef int DataType;
////class Stack
////{
////public:
////	Stack(size_t capacity = 3)
////	{
////		cout << "size_t capacity = 3" << endl;
////		_array = (DataType*)malloc(sizeof(DataType) * capacity);
////		if (NULL == _array)
////		{
////			perror("malloc申请空间失败!!!");
////			return;
////		}
////		_capacity = capacity;
////		_size = 0;
////	}
////	// Stack st2 = st1;
////	Stack(const Stack& st)
////	{
////		_array = (DataType*)malloc(sizeof(DataType) * st._capacity);
////		if (NULL == _array)
////		{
////			perror("malloc申请空间失败!!!");
////			return;
////		}
////		memcpy(_array, st._array, sizeof(DataType)*st._size); //把st1的数据拷贝过来
////
////		_size = st._size;
////		_capacity = st._capacity;
////	}
////	void Push(DataType data)
////	{
////		_array[_size] = data;
////		_size++;
////	}
////
////	bool Empty()
////	{
////		return _size == 0;
////	}
////	DataType Top()
////	{
////		return _array[_size - 1];
////	}
////
////	void Pop()
////	{
////		--_size;
////	}
////
////	~Stack() //浅拷贝崩溃
////	{
////		cout << "~Stack( )" << endl;
////		if (_array)
////		{
////			free(_array);
////			_array = NULL;
////			_capacity = 0;
////			_size = 0;
////		}
////	}
////private:
////	DataType* _array;
////	int _capacity;
////	int _size;
////};
////
////int main()
////{
////	Stack st1(10);
////	st1.Push(1);
////	st1.Push(1);
////	st1.Push(1);
////
////	Stack st2 = st1;
////	st2.Push(2);
////	st2.Push(2);
////
////	while (!st2.Empty())
////	{
////		cout << st2.Top() <<' ';
////		st2.Pop();
////	}
////	cout << endl;
////	while (!st1.Empty())
////	{
////		cout << st1.Top() << ' ';
////		st1.Pop();
////	}
////	cout << endl;
////	return 0;
////}
//
//
//
//
//
//
//// ————————————  拷贝构造函数典型调用场景
//
//#include <iostream>
//using namespace std;
//
//class Date
//{
//public:
//	Date(int year, int minute, int day)
//	{
//		cout << "Date(int,int,int):" << this << endl;
//	}
//	Date(const Date& d)
//	{
//		cout << "Date(const Date& d):" << this << endl;
//	}
//	~Date()
//	{
//		cout << "~Date():" << this << endl;
//	}
//private:
//	int _year;
//	int _month;
//	int _day;
//};
//Date Test(Date d)
//{
//	Date temp(d);
//	return temp;
//}
//int main()
//{
//	Date d1(2022, 1, 13);
//	Test(d1);
//	return 0;
//}
//
